package cn.stylefeng.guns.modular.rest.agv;

import cn.stylefeng.guns.modular.agv.model.params.FeedbackTaskRS;
import cn.stylefeng.guns.modular.agv.model.params.TuskAgvTaskParam;
import cn.stylefeng.guns.modular.agv.service.TuskAgvTaskService;
import cn.stylefeng.guns.modular.agv.util.PriorityParamVo;
import cn.stylefeng.guns.modular.agv.util.StorageRsVo;
import cn.stylefeng.guns.modular.rest.aop.UserAop;
import cn.stylefeng.guns.sys.modular.system.entity.User;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.Date;

/**
 *地址控制器
 */
@Controller
@RequestMapping("/rest/tuskAgvTaskController")
public class RestTuskAgvTaskController extends BaseController {

    @Autowired
    private UserAop userAop;

    @Autowired
    private TuskAgvTaskService tuskAgvTaskService;
    /**
     * 新增接口
     *
     * @author zhangzh
     * @Date 2024-05-14
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(TuskAgvTaskParam tuskAgvTaskParam) {
        User user = userAop.getUser();
        if(user !=null && user.getUserId() != null){
            //创建人
            tuskAgvTaskParam.setCreateUser(user.getUserId());
            //修改人
            tuskAgvTaskParam.setUpdateUser(user.getUserId());
        }
        // 创建时间
        tuskAgvTaskParam.setCreateTime(new Date());
        return tuskAgvTaskService.addTask(tuskAgvTaskParam);
    }

    /**
     * 查询集货存放数据情况
     * @return
     */
    @ResponseBody
    @RequestMapping("/getMapStorage")
    public StorageRsVo getMapStorage() {
        return this.tuskAgvTaskService.getMapStorage();
    }

    @ResponseBody
    @RequestMapping("/getMapStorageByRoadway")
    public StorageRsVo getMapStorageByRoadway(String roadway) {
        return this.tuskAgvTaskService.getMapStorageByRoadway(roadway);
    }

    /**
     * 设置优先级
     * @param priority
     * @return
     */
    @ResponseBody
    @RequestMapping("/setPriority")
    public FeedbackTaskRS setPriority(PriorityParamVo priority) {
        return this.tuskAgvTaskService.setPriority(priority);
    }

    /**
     * 清空通道
     * @param areaName
     * @return
     */
    @ResponseBody
    @RequestMapping("/clear")
    public FeedbackTaskRS clear(String areaName) {
        return this.tuskAgvTaskService.clear(areaName);
    }

    /**
     * 清空所有通道
     * @return
     */
    @ResponseBody
    @RequestMapping("/clearAll")
    public void clearAll() {
        this.tuskAgvTaskService.clearAll();
    }
}
